﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using AutoMapper;

using Happy.Archetype;
using Happy.Application.Domain.CommonModel.TreeLike;
using Happy.Cms.Domain;
using Happy.Cms.Domain.Categories;
using Happy.Cms.Query.Categories;
using Happy.Cms.Domain.Services;

namespace Happy.Cms.Application.Categories
{
    [ApplicationService]
    public sealed class CategoryService : TreeNodeService<Category, CategoryView, ICmsUnitOfWork, ICmsNodePathRepairer>
    {
        protected override Category CreateAggregate(CategoryView viewModel)
        {
            var aggregate = base.CreateAggregate(viewModel);

            return Mapper.Map(viewModel, aggregate);
        }

        protected override Category NewAggregate(CategoryView viewModel, Category parent)
        {
            return new Category(Guid.NewGuid(), parent);
        }

        protected override Category NewAggregate(CategoryView viewModel)
        {
            return new Category(Guid.NewGuid());
        }

        protected override void UpdateAggregate(Category aggregate, CategoryView viewModel)
        {
            base.UpdateAggregate(aggregate, viewModel);

            Mapper.Map(viewModel, aggregate);
        }
    }
}
